package achi.community.irla.database;

//import DatabaseImpl;
import achi.community.irla.beans.SettingsBackBean;
import achi.community.irla.entities.Messages;
//import achi.community.irla.entities.Messages_users;
import achi.community.irla.entities.Users;
import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;

/**
 * ModelBean:
 * Contains logged in customers, choosen shop category
 * Retrive all animals of a specific type(to shop.xhtml)
 * Get data of one animal in DB(to animal.xhtml)
 */
@ManagedBean
@SessionScoped
public class ModelBean implements Serializable {

    @EJB
    DatabaseImpl db;
    private Users user;

    //@ManagedProperty(value = "#{settingsBackBean}")
    //SettingsBackBean settingsBackBean;

    /**
    public void setSettingsBackBean(SettingsBackBean settingsBackBean) {
        this.settingsBackBean = settingsBackBean;
    }

    public SettingsBackBean getSettingsBackBean() {
        return settingsBackBean;
    }
    */

    public Users getUser() {
        return user;
    }

    public void setUser(Users user) {
        this.user = user;
        /**
        settingsBackBean.setFirstname(user.getFirstName());
        settingsBackBean.setLastname(user.getLastName());
        settingsBackBean.setUsername(user.getUsername());
        settingsBackBean.setEmail(user.getEmail());
        */
        System.out.println("user set!");
    }

    public boolean isLoggedin() {
        if (user == null) {
            user = new Users();
        }

        String u = user.getFirstName();
        return u != null;
    }

    public void logout() {
        user = null;
    }

    public List getAllUsers() {
        return db.getAllUsers();
    }

    public List getAllMessages() {
        return db.getAllMessages();
    }

    /**
    public List getAllUMessages(){
    return db.getAllUMessages();
    }

     */
    public List getAllFriends() {
        return db.getAllFriends();
    }

    public List getAllAchievements() {
        return db.getAllAchievements();
    }

    public List getAllAchievements_comments() {
        return db.getAllAchievements_comments();
    }

    public List getAllAchievements_completed() {
        return db.getAllAchievements_completed();
    }

    public List getAllAchievements_suggested() {
        return db.getAllAchievements_suggested();
    }

    public List getAllAchievements_target() {
        return db.getAllAchievements_target();
    }
    /**
    private Customer customer;
    private String category;
    private Animal currentAnimal;

    public Animal getCurrentAnimal() {
    return currentAnimal;
    }

    public void setCurrentAnimal(Animal currentAnimal) {
    this.currentAnimal = currentAnimal;
    }

    public String getCategory() {
    return category;
    }

    public void setCategory(String category) {
    this.category = category;
    }
    
    public Customer getCustomer() {
    return customer;
    }

    public void setCustomer(Customer customer) {
    this.customer = customer;
    }

    public LinkedList<Animal> getAnimalsQualified() {
    List<Animal> list = db.getAnimals();
    LinkedList a = new LinkedList();
    for (int i = 0; i < list.size(); i++) {
    if (list.get(i).getCategory().equals(category))
    a.add(list.get(i));
    }
    return a;
    }

    public void setCurrentAnimal(int id) {
    this.currentAnimal = db.getAnimal(id);
    }

    public boolean isLoggedin() {
    if (customer == null) {
    customer = new Customer();
    }

    String cust = customer.getFirstName();
    return cust != null;
    }

    public boolean isAdmin() {
    return customer.isAdm();
    }

    public List<PurchaseOrder> getOrders(){
    List<PurchaseOrder> orders = db.getOrders(customer.getId().intValue());
    return orders;
    }
     * */
}
